package union

class AreasOrganograma {
	
	Area area
	Area areaSuperior
	Organograma organograma
	NivelHierarquico nivel
	
	static belongsTo = NivelHierarquico
	
	static AreasOrganograma link(area, organograma)
	{
		def m = AreasOrganograma.findByAreaAndOrganograma(area, organograma)
		if(!m){
			m = new AreasOrganograma()
			area?.addToAreasOrganograma(m)
			organograma?.addToAreasOrganograma(m)
			m.save()
		}
		return m
	}
	
	static void unlink(area, organograma){
		def m = AreasOrganograma.findByAreaAndOrganograma(area, organograma)
		if(m){
			area?.removeFromAreasOrganogramas(m)
			organograma?.removerFromAreasOrganogramas(m)
			m.delete()
		}		
	}
	
    static constraints = {
    }	
	
}
